Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.3, n = 274)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.52689 11.56599 11.60472 11.64308 11.68109 11.71874 11.75605 11.79303
## [9] 11.82969 11.86602 11.90205 11.93778 11.97321 12.00833 12.04314 12.07761
## [17] 12.11174 12.14553 12.17895 12.21201 12.24486 12.27759 12.31014 12.34244
## [25] 12.37441 12.40599 12.43709 12.46765 12.49759 12.52746 12.55768 12.58793
## [33] 12.61791 12.64731 12.67583 12.70316 12.73052 12.75906 12.78839 12.81811
## [41] 12.84783 12.87715 12.90567 12.93300 12.95874 12.98249 13.00385 13.02243
## [49] 13.04079 13.06092 13.08155 13.10143 13.11930 13.13391 13.14400 13.15052
## [57] 13.15529 13.15830 13.15956 13.15907 13.15682 13.15284 13.14711 13.13964
## [65] 13.13044 13.11950 13.10683 13.09243 13.07630 13.05845 13.03538 13.00500
## [73] 12.96942 12.93075 12.89110 12.85259 12.81732 12.78740 12.75636 12.71824
## [81] 12.67593 12.63235 12.59039 12.55295 12.52294 12.49723 12.47095 12.44438
## [89] 12.41781 12.39150 12.36573 12.34079 12.31696 12.29451 12.27372 12.25487
## [97] 12.23824 12.22464 12.21410 12.20578 12.19880 12.19231 12.18545 12.17735
## [105] 12.16929 12.16293 12.15800 12.15425 12.15142 12.14924 12.14744 12.14577
## [113] 12.14397 12.14305 12.14390 12.14603 12.14899 12.15229 12.15547 12.15806
## [121] 12.16096 12.16526 12.17074 12.17720 12.18443 12.19222 12.20037 12.20866
## [129] 12.21690 12.22486 12.23235 12.23915 12.24506 12.24987 12.25424 12.25891
## [137] 12.26379 12.26882 12.27390 12.27895 12.28390 12.28866 12.29315 12.29729
## [145] 12.30100 12.30419 12.30394 12.29849 12.28951 12.27867 12.26764 12.25809
## [153] 12.25170 12.25013 12.25506 12.26369 12.27223 12.28088 12.28984 12.29930
## [161] 12.30946 12.32052 12.33268 12.34613 12.36107 12.37771 12.39623 12.42114
## [169] 12.45466 12.49354 12.53452 12.57436 12.60978 12.63755 12.66386 12.69636
## [177] 12.73400 12.77571 12.82044 12.86713 12.91472 12.96214 13.00833 13.05225
## [185] 13.09283 13.12900 13.15972 13.18391 13.20052 13.20850 13.21019 13.20885
## [193] 13.20476 13.19820 13.18945 13.17880 13.16653 13.14927 13.12417 13.09223
## [201] 13.05447 13.01188 12.96550 12.91631 12.86534 12.81360 12.76210 12.71184
## [209] 12.66384 12.61911 12.57866 12.53900 12.49638 12.45139 12.40464 12.35672
## [217] 12.30824 12.25979 12.21198 12.16541 12.12067 12.07837 12.03911 12.00110
## [225] 11.96249 11.92383 11.88564 11.84845 11.81279 11.77920 11.74647 11.71322
## [233] 11.67978 11.64644 11.61351 11.58130 11.55011 11.52025 11.49202 11.46574
## [241] 11.44170 11.42021 11.40158 11.38611 11.37252 11.35956 11.34757 11.33692
## [249] 11.32796 11.32103 11.31651 11.31473 11.31606 11.31972 11.32484 11.33164
## [257] 11.34031 11.35106 11.36409 11.37961 11.39748 11.41745 11.43952 11.46366
## [265] 11.48989 11.51820 11.54857 11.58102 11.61553 11.65210 11.69072 11.73140
## [273] 11.77412 11.81889
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.3, n = 274)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.71824 10.81044 10.90079 10.98927 11.07588 11.16058 11.24338 11.32424
## [9] 11.40317 11.48014 11.55514 11.62815 11.69916 11.76815 11.83515 11.90020
## [17] 11.96334 12.02460 12.08402 12.14166 12.19723 12.25054 12.30170 12.35083
## [25] 12.39806 12.44350 12.48726 12.52948 12.57026 12.60897 12.64511 12.67900
## [33] 12.71096 12.74131 12.77037 12.79845 12.82468 12.84811 12.86899 12.88755
## [41] 12.90404 12.91870 12.93177 12.94350 12.95412 12.96388 12.97302 12.98178
## [49] 12.98760 12.98874 12.98668 12.98288 12.97882 12.97596 12.97579 12.97701
## [57] 12.97741 12.97703 12.97593 12.97419 12.97184 12.96897 12.96561 12.96184
## [65] 12.95771 12.95328 12.94862 12.94377 12.93879 12.93376 12.92921 12.92534
## [73] 12.92168 12.91775 12.91307 12.90718 12.89959 12.88982 12.87856 12.86676
## [81] 12.85441 12.84148 12.82796 12.81381 12.79901 12.78372 12.76809 12.75207
## [89] 12.73565 12.71878 12.70143 12.68357 12.66516 12.64618 12.62660 12.60637
## [97] 12.58546 12.56391 12.54168 12.51869 12.49482 12.46999 12.44410 12.41705
## [105] 12.38446 12.34366 12.29713 12.24733 12.19674 12.14782 12.10304 12.06487
## [113] 12.03579 12.00712 11.97103 11.93124 11.89146 11.85541 11.82681 11.80936
## [121] 11.80031 11.79427 11.79099 11.79026 11.79185 11.79552 11.80104 11.80819
## [129] 11.81674 11.82646 11.83711 11.84847 11.86032 11.87241 11.88787 11.90930
## [137] 11.93569 11.96603 11.99931 12.03452 12.07064 12.10668 12.14161 12.17444
## [145] 12.20414 12.22971 12.25568 12.28638 12.32054 12.35685 12.39403 12.43080
## [153] 12.46586 12.49792 12.52570 12.54958 12.57110 12.59064 12.60859 12.62535
## [161] 12.64131 12.65686 12.67240 12.68831 12.70499 12.72284 12.74224 12.76323
## [169] 12.78524 12.80778 12.83032 12.85237 12.87341 12.89295 12.91363 12.93802
## [177] 12.96548 12.99535 13.02700 13.05976 13.09299 13.12605 13.15829 13.18905
## [185] 13.21770 13.24357 13.26604 13.28444 13.29813 13.30646 13.31158 13.31582
## [193] 13.31884 13.32028 13.31979 13.31702 13.31161 13.30336 13.29238 13.27884
## [201] 13.26292 13.24478 13.22459 13.20252 13.17873 13.15339 13.12667 13.09875
## [209] 13.06978 13.03993 13.00938 12.97626 12.93904 12.89833 12.85475 12.80893
## [217] 12.76149 12.71306 12.66426 12.61571 12.56804 12.52187 12.47782 12.42897
## [225] 12.37061 12.30669 12.24119 12.17805 12.12125 12.07475 12.03444 11.99374
## [233] 11.95291 11.91217 11.87177 11.83195 11.79296 11.75503 11.71841 11.68334
## [241] 11.65006 11.61881 11.58984 11.56338 11.53805 11.51269 11.48788 11.46420
## [249] 11.44223 11.42255 11.40573 11.39236 11.38302 11.37682 11.37254 11.37025
## [257] 11.37000 11.37185 11.37587 11.38212 11.39055 11.40110 11.41375 11.42851
## [265] 11.44537 11.46434 11.48542 11.50859 11.53387 11.56124 11.59072 11.62229
## [273] 11.65596 11.69172
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.3, n = 274)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.82891 10.89317 10.95626 11.01815 11.07882 11.13823 11.19636 11.25317
## [9] 11.30865 11.36275 11.41544 11.46671 11.51652 11.56491 11.61197 11.65775
## [17] 11.70229 11.74561 11.78777 11.82879 11.86829 11.90597 11.94201 11.97660
## [25] 12.00993 12.04216 12.07350 12.10413 12.13423 12.16190 12.18584 12.20713
## [33] 12.22686 12.24612 12.26599 12.28756 12.31027 12.33279 12.35504 12.37692
## [41] 12.39834 12.41922 12.43947 12.45900 12.47772 12.49555 12.51239 12.52815
## [49] 12.54528 12.56524 12.58650 12.60756 12.62688 12.64294 12.65422 12.66165
## [57] 12.66725 12.67114 12.67343 12.67424 12.67367 12.67185 12.66887 12.66487
## [65] 12.65994 12.65422 12.64779 12.64079 12.63333 12.62551 12.61637 12.60513
## [73] 12.59220 12.57796 12.56282 12.54718 12.53143 12.51599 12.49836 12.47670
## [81] 12.45241 12.42686 12.40142 12.37749 12.35643 12.33568 12.31219 12.28658
## [89] 12.25952 12.23164 12.20359 12.17602 12.14956 12.12486 12.10257 12.08333
## [97] 12.06778 12.05529 12.04450 12.03501 12.02643 12.01833 12.01033 12.00200
## [105] 11.99492 11.99047 11.98796 11.98671 11.98603 11.98524 11.98365 11.98058
## [113] 11.97535 11.96941 11.96446 11.96023 11.95641 11.95272 11.94886 11.94455
## [121] 11.94077 11.93854 11.93762 11.93777 11.93872 11.94024 11.94208 11.94399
## [129] 11.94573 11.94704 11.94769 11.94741 11.94598 11.94313 11.93736 11.92784
## [137] 11.91535 11.90067 11.88460 11.86790 11.85137 11.83578 11.82192 11.81057
## [145] 11.80252 11.79854 11.79509 11.78889 11.78110 11.77286 11.76535 11.75972
## [153] 11.75714 11.75875 11.76572 11.77690 11.79024 11.80552 11.82255 11.84112
## [161] 11.86104 11.88210 11.90411 11.92686 11.95014 11.97377 11.99753 12.02536
## [169] 12.05974 12.09830 12.13864 12.17840 12.21518 12.24662 12.27818 12.31623
## [177] 12.35975 12.40769 12.45902 12.51272 12.56775 12.62307 12.67766 12.73049
## [185] 12.78051 12.82671 12.86804 12.90348 12.93199 12.95254 12.96814 12.98227
## [193] 12.99460 13.00478 13.01248 13.01737 13.01911 13.01670 13.00966 12.99844
## [201] 12.98348 12.96522 12.94411 12.92059 12.89511 12.86811 12.84004 12.81134
## [209] 12.78246 12.75384 12.72592 12.69522 12.65862 12.61714 12.57182 12.52366
## [217] 12.47369 12.42293 12.37240 12.32312 12.27611 12.23239 12.19299 12.15103
## [225] 12.10125 12.04710 11.99199 11.93938 11.89269 11.85537 11.82472 11.79577
## [233] 11.76853 11.74301 11.71919 11.69709 11.67670 11.65803 11.64108 11.62586
## [241] 11.61235 11.60058 11.59053 11.58221 11.57687 11.57523 11.57654 11.58003
## [249] 11.58494 11.59051 11.59597 11.60056 11.60351 11.60637 11.61095 11.61691
## [257] 11.62390 11.63157 11.63958 11.64759 11.65581 11.66467 11.67419 11.68437
## [265] 11.69521 11.70671 11.71888 11.73172 11.74523 11.75943 11.77430 11.78985
## [273] 11.80609 11.82303
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")